package br.com.comanda.webservice.model;

// Generated 08/05/2012 22:04:45 by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.sun.xml.internal.bind.CycleRecoverable;

@XmlRootElement
@Entity
@Table(name = "user", catalog = "comanda")
public class User implements Serializable, CycleRecoverable {

	private static final long serialVersionUID = 7084682286204819121L;

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	private Integer id;

	@Column(name = "login", nullable = false, length = 45)
	private String login;

	@Column(name = "password", nullable = false, length = 45)
	private String password;

	@XmlTransient
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
	private Set<Account> accounts = new HashSet<Account>(0);

	public User() {
	}

	public User(String login, String password) {
		this.login = login;
		this.password = password;
	}

	public User(String login, String password, Set<Account> accounts) {
		this.login = login;
		this.password = password;
		this.accounts = accounts;
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getLogin() {
		return this.login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Set<Account> getAccounts() {
		return this.accounts;
	}

	public void setAccounts(Set<Account> accounts) {
		this.accounts = accounts;
	}

	public Object onCycleDetected(Context context) {
		User user = new User();
		user.setId(this.id);
		return user;
	}

}
